package demo1;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:要写一个可以存放各种类型的数组
 * User: 张宇田
 * Date: 2025-08-16
 * Time: 10:04
 */
public class MyArray {
    public Object[] arr = new Object[15];

    public Object getPos(int pos){
        return arr[pos];
    }

    public void setVal(int pos , Object ob){
        arr[pos] = ob;
    }
}
class TestDemo{
    public static void main(String[] args) {
        MyArray ma = new MyArray();
        ma.setVal(1,10);
        ma.setVal(2, 122);
        ma.setVal(3, "das");
        ma.setVal(4, "das");
       // ma.setVal(4, new ArrayList<>(1));
        ma.setVal(5, new ArrayList<>(2));
        //啥也能放

        //int i = ma.getPos(1);    这样就不能接受
        int i = (int) ma.getPos(1);  // 强制类型转换
        Object b = ma.getPos(3);
        Object c = ma.getPos(4);
       // System.out.println(i + "" +b);




    }
}
